package com.yhthu.query;

import com.yhthu.bean.Instruction;

/**
 * 指令工厂
 *
 * @author yanghao1
 */
public class QueryFactory {

    /**
     * 获取指令对象
     *
     * @param instruction 指令
     * @return
     */
    public BaseQuery getQuery(Instruction instruction) {
        if (instruction == null) {
            System.out.println("指令为空");
            return null;
        }
        // 根据指令初始化不同类型的指令对象
        if (instruction.getCommand().equalsIgnoreCase("update")) {
            return new Update();
        } else if (instruction.getCommand().equalsIgnoreCase("donation")) {
            return new Donation();
        } else if (instruction.getCommand().equalsIgnoreCase("delete")) {
            return new Delete();
        } else if (instruction.getCommand().equalsIgnoreCase("query")) {
            return new Query();
        }
        return null;
    }
}
